package com.erp.myAdapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.erp.R
import com.erp.bean.ZhuanMaiDianBean
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_zhuanmaidian.view.*


/**
 * Created by Administrator on 2018/1/26/026.
 * 作者：刘洋
 */

class ZhuanMaiDianAdapter(private val mlist: List<ZhuanMaiDianBean>, private val mcontext: Context) : BaseAdapter() {
    private val minflater: LayoutInflater = LayoutInflater.from(mcontext)
    override fun getCount(): Int {
        return mlist.size
    }

    override fun getItem(i: Int): Any {
        return mlist[i]
    }

    override fun getItemId(i: Int): Long {
        return i.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v : View
        val h: ViewHolder
        if (convertView == null) {
            v = minflater.inflate(R.layout.lv_zhuanmaidian, null)
            h = ViewHolder(v)
            v.tag = h
        } else {
            v=convertView
            h = convertView.tag as ViewHolder
        }
        val bean = mlist[position]
        Myutil.settv(bean.name, h.tvYonghuming)
        Myutil.settv(bean.alias_name, h.tvBieming)
        Myutil.settv(bean.id_num, h.tvId)
        Myutil.settv(Myutil.getdata(bean.created), h.tvTime)
        Myutil.settv(bean.area_name, h.tvQuyu)
        Myutil.settv(bean.province, h.tvShengfen)
        if(bean.status == "0"){
            Myutil.settv("不活跃", h.tvZhaungtai)
        }else if(bean.status == "1"){
            Myutil.settv("活跃", h.tvZhaungtai)
        }
        if(bean.withdraw_es == "0"){
            Myutil.settv("已撤店", h.tvChedian)
        }else if(bean.withdraw_es == "1"){
            Myutil.settv("未撤店", h.tvChedian)
        }
        Myutil.settv(Myutil.getdata(bean.join_time), h.tvJiamengTime)
        Myutil.settv(Myutil.getdata(bean.expire_time), h.tvDaoqiTime)
        Myutil.settv(Myutil.getdata(bean.ctime), h.fangwenTime)
        return v
    }

    internal class ViewHolder(v: View) {
        var tvYonghuming: TextView = v.tv_yonghuming
        var tvBieming: TextView = v.tv_bieming
        var tvId: TextView = v.tv_id
        var tvTime: TextView = v.tv_time
        var tvQuyu: TextView = v.tv_quyu
        var tvShengfen: TextView = v.tv_shengfen
        var tvZhaungtai: TextView = v.tv_zhaungtai
        var tvChedian: TextView = v.tv_chedian
        var textView4: TextView = v.textView4
        var tvJiamengTime: TextView = v.tv_jiameng_time
        var tvDaoqiTime: TextView = v.tv_daoqi_time
        var fangwenTime: TextView = v.fangwen_time
    }
}
